package com.dabai.linktools.activitys;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.dabai.linktools.R;
import com.dabai.linktools.databinding.ActivityEditTextDataBinding;
import com.dabai.linktools.utils.DabaiUtils;
import com.dabai.linktools.utils.Patterns;
import com.dabai.utils.DateUtils;
import com.google.android.material.bottomsheet.BottomSheetDialog;

import java.util.ArrayList;
import java.util.Map;
import java.util.regex.Matcher;

public class EditTextDataActivity extends AppCompatActivity {


    private String link,nolink;
    private BottomSheetDialog bsd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        bsd = new BottomSheetDialog(this);
        bsd.setContentView(R.layout.activity_edit_text_data);

        bsd.show();

        bsd.setOnDismissListener(dialogInterface -> finish());

        CharSequence text = getIntent()
                .getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);

        nolink = text+"";

        Matcher matcher = Patterns.WEB_URL.matcher(nolink);
        if (matcher.find()) {
            link = matcher.group();
        }

        TextView te1 = bsd.findViewById(R.id.textView1);
        TextView te2 = bsd.findViewById(R.id.textView2);

        te1.setText(""+nolink);
        te2.setText(link);

    }


    /**
     * 提交与获取
     *
     * @param key
     * @param value
     */
    public void set_sharedString(String key, String value) {
        SharedPreferences sp = this.getSharedPreferences("Collection", 0);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public String get_sharedString(String key, String moren) {
        SharedPreferences sp = this.getSharedPreferences("Collection", 0);
        return sp.getString(key, moren);
    }


    public void collection1(View view) {
        set_sharedString(DateUtils.getNowTime(3),nolink);
        Toast.makeText(this, "收藏成功!", Toast.LENGTH_SHORT).show();
        bsd.dismiss();
    }

    public void collection2(View view) {
        set_sharedString(DateUtils.getNowTime(3),link);
        Toast.makeText(this, "收藏成功!", Toast.LENGTH_SHORT).show();
        bsd.dismiss();
    }
}
